package cn.rongdao.jrkabao.ui.deposit.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.mifengkong.frwidget.recyclerview.PtrRecyclerViewUIComponent;
import com.mifengkong.frwidget.refersh.OnPullToRefreshListener;

import butterknife.BindView;
import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.base.BaseFragment;
import cn.rongdao.jrkabao.ui.cashadvance.uicomponent.CashEmptyUIComponent;
import cn.rongdao.jrkabao.ui.deposit.adapter.IncomeAndExpenditureAdapter;

/**
 * Created by jack on 2017/7/27
 */

public abstract class BaseFragmentIncomeAndExpenditure extends BaseFragment {

    @BindView(R.id.fiae_ptr_framelayout)
    PtrRecyclerViewUIComponent ptrRecyclerViewUIComponent;
    @BindView(R.id.fiae_empty_view)
    CashEmptyUIComponent emptyView;

    protected IncomeAndExpenditureAdapter mAdapter;

    @Override
    protected int layoutRes() {
        return R.layout.fragment_income_and_expenditure;
    }

    @Override
    protected void onViewReallyCreated(View view) {
        super.onViewReallyCreated(view);

        mAdapter = new IncomeAndExpenditureAdapter(getContext());
        ptrRecyclerViewUIComponent.setBackground(R.color.layout_bg);
        ptrRecyclerViewUIComponent.setLayoutManager(new LinearLayoutManager(getContext()));
        ptrRecyclerViewUIComponent.setAdapter(mAdapter);

        initListener();
    }

    private void initListener() {
        ptrRecyclerViewUIComponent.delayRefresh();
        ptrRecyclerViewUIComponent.setOnPullToRefreshListener(new OnPullToRefreshListener() {
            @Override
            public void onPullToRefresh() {
                requestData();
            }
        });
    }

    protected void runUiThread() {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ptrRecyclerViewUIComponent.refreshComplete();
            }
        });
    }

    protected abstract void requestData();
}
